#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Time   :2021/1/26
# @Author :CJX
# @File   :kill_all.py

import os
import re
import signal


# execute command, and return the information. 执行命令并返回命令输出信息
def execCmd(cmd):
    r = os.popen(cmd)
    text = r.read()
    r.close()
    return text


def stopChild():
    processInfo = os.popen("ps -ef|grep watchdog.py|grep -v grep|awk '{print $2}'").readlines()
    for pid in processInfo:
        os.kill(int(pid), signal.SIGKILL)


# stop parent
def stopParent():
    parentList = os.popen("ps -ef|grep watchdog.py|grep -v grep|awk '{print $2}'").readlines()
    for pid in parentList:
        os.kill(int(pid), signal.SIGKILL)


def stopAll():
    stopChild()
    stopParent()


if __name__ == '__main__':
    stopAll()
